package cn.xuan.zp.service.user.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.xuan.zp.db.domain.User;
import cn.xuan.zp.db.domain.UserExample;
import cn.xuan.zp.db.domain.UserExample.Criteria;
import cn.xuan.zp.db.mapper.UserMapper;
import cn.xuan.zp.service.user.IUserService;

@Service
public class UserServiceImpl implements IUserService {
	
	@Autowired
	UserMapper userMapper;

	@Override
	public int addEnity(User enity) throws Exception {
		int i = userMapper.insertSelective(enity);
		return i;
	}

	@Override
	public int updateEnity(User enity) throws Exception {
		int i = userMapper.updateByPrimaryKeySelective(enity);
		return i;
	}

	@Override
	public Object queryAll() throws Exception {
		UserExample example = new UserExample();
		return userMapper.selectByExample(example );
	}

	@Override
	public Object queryEnity(Object... params) throws Exception {
		/*if(params != null && params.length > 0) {
			params
		} */
		return null;
	}

	@Override
	public List<User> queryUserByLoginName(String loginName) throws Exception {
		UserExample example = new UserExample();
		
		Criteria criteria = example.createCriteria();
		
		criteria.andLoginNameEqualTo(loginName);
		
		return userMapper.selectByExample(example);
	}

	@Override
	public User getByPrimaryKey(long id) {
		return userMapper.selectByPrimaryKey(id);
	}

}
